﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Media;
using System.Text;
using System.Threading.Tasks;

namespace Tetris.Game.Common.TetrisCenter
{
    public class SoundManager : IDisposable
    {
        private static Lazy<SoundManager> _instance = new Lazy<SoundManager>(() => new SoundManager());
        private SoundPlayer _player;
        private SoundManager()
        {
            _player = new SoundPlayer();
        }
        public static SoundManager Instance => _instance.Value;
        public void PlaySound(string soundFilePath)
        {
            _player.SoundLocation = soundFilePath;
            _player.Load();
            _player.Play();
        }
        public void PlaySound(Stream stream)
        {
            stream.Position = 0;
            _player.Stream = stream;
            _player.Play();
        }
        public void StopSound()
        {
            _player.Stop();
        }
        public void Dispose()
        {
            _player?.Dispose();
        }
        ~SoundManager()
        {
            Dispose();
        }
    }
}
